package com.jappit.runtracker.screens;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;

import com.jappit.runtracker.model.Run;
import com.jappit.runtracker.utils.AppUtils;
import com.jappit.runtracker.utils.FormatUtils;

public class RunDetailsScreen extends Form implements CommandListener
{
	Command backCommand = null;
	
	public RunDetailsScreen(Run run)
	{
		super("Run details");
		
		System.out.println("START END: " + run.getStartDate().getTime() + ", " + run.getEndDate().getTime());
		
		append(new StringItem("Started", FormatUtils.formatDateTime(run.getStartDate())));

		append(new StringItem("Ended", FormatUtils.formatDateTime(run.getEndDate())));
		
		append(new StringItem("Distance", FormatUtils.formatDistance(run.getDistance())));
		
		long duration = run.getDuration();
		
		double averageSpeed = run.getAverageSpeed();
		
		append(new StringItem("Duration", FormatUtils.formatDuration(duration)));
		
		append(new StringItem("Average speed", FormatUtils.formatSpeed(averageSpeed)));
		
		addCommand(backCommand = new Command("Back", Command.BACK, 1));
		setCommandListener(this);
	}
	public void commandAction(Command c, Displayable d)
	{
		if(c == backCommand)
		{
			AppUtils.getInstance().gotoPreviousScreen();
		}
	}
}
